package com.wgh.api.client.fallback;

import com.wgh.api.client.search.SearchClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * 搜索服务客户端熔断降级实现
 */
@Component
public class SearchClientFallback implements SearchClient {

    private static final Logger log = LoggerFactory.getLogger(SearchClientFallback.class);

    @Override
    public Map<String, Object> searchProducts(Map<String, Object> searchParams) {
        log.error("搜索服务调用失败，降级处理：searchProducts(searchParams={})", searchParams);
        Map<String, Object> result = new HashMap<>();
        result.put("code", "500");
        result.put("message", "搜索服务暂时不可用，请稍后再试");
        result.put("items", Collections.emptyList());
        result.put("total", 0);
        return result;
    }

    @Override
    public Map<String, Object> getSuggestions(String keyword) {
        log.error("搜索服务调用失败，降级处理：getSuggestions(keyword={})", keyword);
        Map<String, Object> result = new HashMap<>();
        result.put("code", "500");
        result.put("message", "搜索建议服务暂时不可用");
        result.put("suggestions", Collections.emptyList());
        return result;
    }

    @Override
    public Map<String, Object> getHotWords() {
        log.error("搜索服务调用失败，降级处理：getHotWords()");
        Map<String, Object> result = new HashMap<>();
        result.put("code", "500");
        result.put("message", "热门搜索词服务暂时不可用");
        result.put("hotWords", Collections.emptyList());
        return result;
    }

    @Override
    public Map<String, Object> searchCategories(Map<String, Object> params) {
        log.error("搜索服务调用失败，降级处理：searchCategories(params={})", params);
        Map<String, Object> result = new HashMap<>();
        result.put("code", "500");
        result.put("message", "分类搜索服务暂时不可用");
        result.put("categories", Collections.emptyList());
        return result;
    }

    @Override
    public Map<String, Object> getFilterOptions(Map<String, Object> params) {
        log.error("搜索服务调用失败，降级处理：getFilterOptions(params={})", params);
        Map<String, Object> result = new HashMap<>();
        result.put("code", "500");
        result.put("message", "搜索过滤服务暂时不可用");
        result.put("filters", Collections.emptyMap());
        return result;
    }
}